package com.systop.ltbook.order.webapp;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;

import com.systop.cms.utils.PageUtil;
import com.systop.core.dao.support.Page;
import com.systop.core.webapp.struts2.action.DefaultCrudAction;
import com.systop.ltbook.order.model.OrderForm;
import com.systop.ltbook.order.model.OrderItem;
import com.systop.ltbook.order.service.OrderFormManager;
import com.systop.ltbook.order.service.OrderItemManager;

@SuppressWarnings("serial")
@Controller
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class OrderItemAction extends
		DefaultCrudAction<OrderItem, OrderItemManager> {
	public OrderForm orderForm = new OrderForm();
	
	public String orderFormSn;
	@Autowired
	private OrderFormManager orderFormManager;
	/**
	 * 根据OrderForm的id得到OrderForm所关联的所有OrderItem
	 */
	@SuppressWarnings("unchecked")
	@Override
	public String index() {
		
		
		Assert.notNull(orderForm.getId());
		orderForm = orderFormManager.get(orderForm.getId());
		orderFormSn = orderForm.getSn();
		
		String hql = "from OrderItem oi where oi.orderForm.id = ?";
		List args = new ArrayList();
		args.add(orderForm.getId());

		Page page = PageUtil.getPage(getPageNo(), getPageSize());
		page = getManager().pageQuery(page, hql, args.toArray());
		restorePageData(page);

		return INDEX;
	}

	public OrderForm getOrderForm() {
		return orderForm;
	}

	public void setOrderForm(OrderForm orderForm) {
		this.orderForm = orderForm;
	}

	public String getOrderFormSn() {
		return orderFormSn;
	}

}
